Vector3¶

represents point or position, velocity and scale. Note! Angular velocity can not be represented by this type, it should be represented by Transform. It is a class inheriting numpy.ndarray, so it is also ndarray.

In [1]:
from py3d import Vector3
Vector3()
Welcome to py3d world, please visit https://tumiz.github.io/scenario/ for more information
Out[1]:
Vector3([0., 0., 0.])
In [3]:
Vector3(x=1.2)
Out[3]:
Vector3([1.2, 0. , 0. ])
In [5]:
Vector3(x=1, y=3, z=-2.4)
Out[5]:
Vector3([ 1. ,  3. , -2.4])
In [7]:
Vector3(x=1, y=3, z=-2.4, n=(2,))
Out[7]:
Vector3([[ 1. ,  3. , -2.4],
         [ 1. ,  3. , -2.4]])

Get unit vector

In [9]:
Vector3().U
Out[9]:
Vector3([0., 0., 0.])

Get length

In [11]:
Vector3([1,2,3]).L
Out[11]:
array([3.74165739])
In [12]:
Vector3([
    [1,2,3],
    [4,5,6]]).L
Out[12]:
array([[3.74165739],
       [8.77496439]])

Get a random vector

In [14]:
Vector3.Rand()
Out[14]:
Vector3([0.89080463, 0.32286414, 0.63777564])

Get a random vector list

In [15]:
Vector3.Rand(3)
Out[15]:
Vector3([[0.00387297, 0.02409548, 0.39490203],
         [0.01154913, 0.05903717, 0.44225386],
         [0.81956006, 0.51993048, 0.3481314 ]])

Cross product

In [16]:
Vector3(x=3).cross(Vector3(y=2))
Out[16]:
Vector3([0., 0., 6.])

Display points

In [18]:
import plotly.express as px
p = Vector3.Rand(10).cumsum(axis=0)
fig = px.scatter_3d(x=p.x, y=p.y, z=p.z)
fig.show()

Use Vector3 as 2d vector

In [20]:
p=(Vector3.Rand(100)-0.5).U
fig = px.scatter_3d(x=p.x, y=p.y, z=p.z)
fig.show()